define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order/index' + location.search,
                    add_url: 'order/order/add',
                    edit_url: 'order/order/edit',
                    del_url: 'order/order/del',
                    multi_url: 'order/order/multi',
                    table: 'order',
                    refund_url:'order/order/refund'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'order_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_id', title: '订单id'},
                        {field: 'order_sn', title: '订单号'},
                        {field: 'uid', title: '用户id'},
                        {field: 'nickname', title: '用户昵称'},
                        {field: 'createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange'},
                        {field: 'type', title: '咨询类型'},
                        {field: 'status', title: '状态'},
                        {field: 'appoint_time', title: '约定时间', operate:'RANGE', addclass:'datetimerange'},
                        {field: 'pay_status', title: '是否支付'},
                        {field: 'pay_time', title: '支付时间', operate:'RANGE', addclass:'datetimerange'},
                        {field: 'order_sn', title: '订单号码'},
                        {field: 'pay_type', title: '支付时间'},
                        {field: 'experts_id', title: '专家名称'},
                        {field: 'price', title: '支付金额', operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table,  events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },
        refund : function () {
          Controller.api.bindevent();
        }
    };
    return Controller;
});